/**	
 * <br>
 * Copyright 2012 Chuan. All rights reserved.<br>
 * <br>			 
 * Package: com.chuan.mantu <br>
 * FileName: WelcomeActivity.java <br>
 * <br>
 * @version
 * @author javacyc@qq.com
 * @created 2012-11-15
 * @last Modified 
 * @history
 */

package com.chuan.mantu;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.ImageView;

import com.chuan.mantu.sql.DBManager;
import com.chuan.mantu.utils.ConnectionDetector;
import com.chuan.mantu.utils.Const;
import com.chuan.mantu.utils.DirUtil;

/**
 * {欢迎界面}
 *  
 *  @author javacyc@qq.com
 *  @created 2012-11-15 上午09:01:12
 *  @lastModified       
 *  @history           
 */

public class WelcomeActivity extends Activity {

	private DBManager dbManager;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.welcome);
		
		dbManager = new DBManager(this);
		ConnectionDetector connectionDetector = new ConnectionDetector(this);
		//不使用2G/3G网络
		if(dbManager.getConfig(Const.CONFIG_INTENET_MOBILE).equals("0")){
			Const.VALID_INTENET = connectionDetector.isWifiConnection();
		}else{
			Const.VALID_INTENET = connectionDetector.isConnection();
		}
		ImageView welcome = (ImageView) findViewById(R.id.img_welcome);
		AlphaAnimation anim = new AlphaAnimation(0.0f, 1.0f);
		anim.setDuration(1000);
		anim.setAnimationListener(new AnimationListener() {

			@Override
			public void onAnimationStart(Animation arg0) {
				DirUtil dirUtil = new  DirUtil();
				dirUtil.createPicRootDir(WelcomeActivity.this);
				dirUtil.createPicDir(WelcomeActivity.this);
				for(String categoryname : getResources().getStringArray(R.array.category_filename)){
					dirUtil.createCategoryPicDir(WelcomeActivity.this, categoryname);					
				}
			}

			@Override
			public void onAnimationRepeat(Animation arg0) {

			}

			@Override
			public void onAnimationEnd(Animation arg0) {
				Intent intent = new Intent(WelcomeActivity.this,MainActivity.class);
				WelcomeActivity.this.startActivity(intent);
				WelcomeActivity.this.finish();
			}
		});
		welcome.setAnimation(anim);
		anim.start();
	}

	@Override
	protected void onDestroy() {
		dbManager.closeDB();
		super.onDestroy();
	}

}